<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>管理员表管理</title>
        <link rel="stylesheet" href="./styles.css">
        <script src="./common.js"></script>

</head>

<body>
    <div class="container">
        <h1>管理员表管理</h1>
        <div id="tableContainer"></div>
        <button onclick="showAddForm()">添加管理员</button>
        <div id="addForm" style="display: none;">
            <input type="text" id="name" placeholder="姓名">
            <input type="text" id="gender" placeholder="性别">
            <input type="number" id="adminNo" placeholder="管理员编号">
            <button onclick="addAdmin()">确认添加</button>
        </div>
    </div>
    <script>
        document.addEventListener('DOMContentLoaded', () => {
            loadTable('admins');
        });

        function showAddForm() {
            document.getElementById('addForm').style.display = 'block';
        }

        async function addAdmin() {
            const data = {
                姓名: document.getElementById('name').value,
                性别: document.getElementById('gender').value,
                管理员编号: parseInt(document.getElementById('adminNo').value)
            };
            const success = await addData('admins', data);
            if (success) {
                alert('管理员添加成功');
                window.location.reload();
            } else {
                alert('管理员添加失败');
            }
        }
    </script>
</body>

</html>